// created by noellynch
// Jun 4, 2009

package com.sceneworker.editors.glslshadereditor;

import java.util.ArrayList;
import java.util.Hashtable;

import javax.swing.JPanel;
import javax.swing.JTextField;

import com.jme.scene.state.GLSLShaderObjectsState;
import com.jme.util.shader.ShaderVariable;
import com.sceneworker.editors.glslshadereditor.uniformreps.Float1Rep;
import com.sceneworker.editors.glslshadereditor.uniformreps.Float2Rep;
import com.sceneworker.editors.glslshadereditor.uniformreps.Float3Rep;
import com.sceneworker.editors.glslshadereditor.uniformreps.Float4Rep;
import com.sceneworker.editors.glslshadereditor.uniformreps.Int1Rep;
import com.sceneworker.editors.glslshadereditor.uniformreps.Int2Rep;
import com.sceneworker.editors.glslshadereditor.uniformreps.Int3Rep;
import com.sceneworker.editors.glslshadereditor.uniformreps.Int4Rep;
import com.sceneworker.editors.glslshadereditor.uniformreps.Mat2Rep;
import com.sceneworker.editors.glslshadereditor.uniformreps.Mat3Rep;
import com.sceneworker.editors.glslshadereditor.uniformreps.Mat4Rep;

public class UniformRepresentations {

	static	private		ArrayList<IUniformRepresentation>		mcla_uniformRep;
	
	static	public	IUniformRepresentation	getRepresentationByClass(Class<?> cl_uniform) {
		if(mcla_uniformRep == null) {
			initialiseUniformReps();
		}
		
		for(IUniformRepresentation lcl_rep : mcla_uniformRep) {
			if(cl_uniform == lcl_rep.getUniformClassRep()) {
				return lcl_rep;
			}
		}
		
		return null;
	}
	
	static	public	IUniformRepresentation		getRepresentationByName(String str_name) {
		if(mcla_uniformRep == null) {
			initialiseUniformReps();
		}
		
		for(IUniformRepresentation lcl_rep : mcla_uniformRep) {
			if(str_name.equals(lcl_rep.getNameRep())) {
				return lcl_rep;
			}
		}
		
		return null;
	}
	
	static	public	ArrayList<IUniformRepresentation>		getAllReps() {
		if(mcla_uniformRep == null) {
			initialiseUniformReps();
		}
		
		return mcla_uniformRep;
	}
	
	public		interface	IUniformRepresentation {
		void						createUniform(GLSLShaderObjectsState cl_state, String str_name);
		String						getNameRep();
		String						getValueRep(ShaderVariable cl_v);
		ArrayList<JTextField>		getUIRep(ShaderVariable cl_v, JPanel cl_parentPanel);
		Class<?>					getUniformClassRep();
		void						updateFromUI(GLSLShaderObjectsState cl_shaderState, ArrayList<JTextField> cla_values, ShaderVariable cl_v);
	}
	
	static	private	void	initialiseUniformReps() {
		mcla_uniformRep = new ArrayList<IUniformRepresentation>();
		mcla_uniformRep.add(new Float1Rep());
		mcla_uniformRep.add(new Float2Rep());
		mcla_uniformRep.add(new Float3Rep());
		mcla_uniformRep.add(new Float4Rep());
		
		mcla_uniformRep.add(new Int1Rep());
		mcla_uniformRep.add(new Int2Rep());
		mcla_uniformRep.add(new Int3Rep());
		mcla_uniformRep.add(new Int4Rep());
		
		mcla_uniformRep.add(new Mat2Rep());
		mcla_uniformRep.add(new Mat3Rep());
		mcla_uniformRep.add(new Mat4Rep());
	}
}
